/**
 * 功能描述
 */

define(function (require, exports, module) {
    module.exports = {
    		total : function(widget,datas){
    			var data = widget.get("editgrid").getData();
				var list = data;
				var dats = [];
				var returnView = {};
				
				var allianceChargesTotal = 0; //联盟酒店费用合计
				var manageChargesTotal = 0; //组团管理费合计
				var otherChargesTotal = 0; //其他费用合计
				var allTotal = 0; //费用总金额
				var depositTotal = 0; //预收款合计
				var deductionChargesTotal = 0; //权证抵扣合计
				var receivableTotal = 0;//应收金额合计
				var receiptsTotal = 0;//实收金额合计
				for(var i in data){
					allianceChargesTotal += (data[i].allianceCharges == "" ? 0 : parseFloat(data[i].allianceCharges));
					manageChargesTotal += (data[i].manageCharges == null ? 0 : parseFloat(data[i].manageCharges));
					otherChargesTotal += (data[i].otherCharges == null ? 0 : parseFloat(data[i].otherCharges));
					depositTotal += (data[i].signUpCharge.payable == null ? 0 : data[i].signUpCharge.payable);
					deductionChargesTotal += (data[i].deductionCharges == null ? 0 : data[i].deductionCharges);
				}
				allTotal = (allianceChargesTotal + manageChargesTotal + otherChargesTotal);
				receivableTotal = (allTotal - depositTotal - deductionChargesTotal);
				returnView.allianceChargesTotal=allianceChargesTotal;
				returnView.manageChargesTotal=manageChargesTotal;
				returnView.otherChargesTotal=otherChargesTotal;
				returnView.allTotal=allTotal;
				returnView.depositTotal=depositTotal;
				returnView.deductionChargesTotal=deductionChargesTotal;
				returnView.receivableTotal=receivableTotal;
				if(datas &&datas.allianceSettlement.balance != null){
					returnView.receiptsTotal=datas.allianceSettlement.balance;
					widget.set("balance", datas.allianceSettlement.balance);
				}else{
					returnView.receiptsTotal=receivableTotal;
				}
				if(datas && datas.allianceSettlement.paymentMethods!=null &&datas.allianceSettlement.paymentMethods.length != 0){
					returnView.paymentMethod=datas.allianceSettlement.paymentMethods;
					widget.set("paymentMethod", datas.allianceSettlement.paymentMethods);
				}else{
					returnView.paymentMethod=[{key:"Cash",value:"现金"}];
				}
				if(datas && datas.allianceSettlement.description != null){
					returnView.description=datas.allianceSettlement.description;
					widget.set("description", datas.allianceSettlement.description);
				}else{
					returnView.description="";
				}
				dats.push(returnView);
				widget.get("totalGrid").setData([]);
				widget.get("totalGrid").setData(dats);
			}
    };
});
